import Data.List
import System.IO
import System.Environment

main = do
    progName <- getProgName
    args <- getArgs    
    let list1 = [1,2,34]
    print list1
    let a = head list1
    print a
    let args0 = args !! 0
    print args0
    let result = solveRPN1  args0
    let resultStr = "result=" ++ "a"
    print "result=" 
    print result

    
solveRPN1 ::  (Num a, Read a)=>String -> a
solveRPN1 = head . foldl foldingFunction [] . words
    where   foldingFunction (x:y:ys) "*" = (x * y):ys
            foldingFunction (x:y:ys) "+" = (x + y):ys
            foldingFunction (x:y:ys) "-" = (y - x):ys


            foldingFunction xs numberString = read numberString:xs
solveCPN1 ::  (Num a, Read a)=>String -> a
solveCPN1 [] [] =  error "maximum of empty list"
solveCPN1 (list1) (x) = x
solveCPN1 (x:xs) = solveCPN1(xs)
            
solveCPNFor ::  (Num a, Read a)=>String -> a
solveCPNFor [] [] =  error "maximum of empty list"
solveCPNFor (list1) (x:xs) = solveCPN1   list1 x
solveCPNFor (x:xs) = solveCPN1(xs)
